﻿using Bigway.Common.Utils;

namespace Bigway.Common.Extensions;

public static class DateOnlyExtensions
{
    public static int GetDurationInDays(this DateOnly startDate, DateOnly endDate)
    {
        if (startDate > endDate)
        {
            (startDate, endDate) = (endDate, startDate);
        }
        var duration = endDate.AddDays(1).ToDateTime() - startDate.ToDateTime();
        return duration.Days;
    }

    public static DateTime ToDateTime(this DateOnly date) 
        => date.ToDateTime(DateTimeKind.Local);

    public static DateTime ToDateTime(this DateOnly date, DateTimeKind kind) 
        => date.ToDateTime(TimeOnly.MinValue, kind);

    public static string ToStandardString(this DateOnly date)
        => date.ToString(CommonStatics.DateFormat);

    public static DateOnly Today()
        => DateOnly.FromDateTime(DateTimeUtils.ChinaToday);

    public static string TodayAsString()
        => Today().ToString(CommonStatics.DateFormat);
}